<?php
    defined('INDEX') or die ('Acesso direto n&atilde;o permitido');
    
    class HTMLComponent
    {
    	protected $scriptsBeforeLoad 	= array();
    	
    	protected $scriptsAfterLoad 	= array();
    	
    	protected $cssFiles				= array();
    	
    	/**
    	 * Returns an array with all requested CSS files.
    	 * 
    	 * @return array $cssFiles
    	 */
    	public function getRequestedCssFiles ()
    	{
    		return $this->cssFiles;
    	}
    	
    	/**
    	 * This function loads an CSS file.
    	 * 
    	 * @param string $relativePath
    	 * 
    	 * @return void
    	 */
    	public function loadCssFile ($relativePath, $media = 'all')
    	{
    		$script = '';
    		
    		if($relativePath != '')
    		{
    			if($media == '')
    			{
    				$media = 'all';
    			}
    			
    			$script = '<link media="'.$media.'" rel="stylesheet" type="text/css" href="'.$relativePath.'"></link>';
    			$this->cssFiles[] = $script;
    		}
    	}
    	
    	/**
    	 * Returns all requested javascript files to load before.
    	 * 
    	 * @return array $scripts
    	 */
    	public function getRequestedBeforeLoadJavascriptFiles ()
    	{
    		return $this->scriptsBeforeLoad;
    	}
    	
    	/**
    	 * Returns all requested javascript files to load after.
    	 * 
    	 * @return array $scripts
    	 */
    	public function getRequestedAfterLoadJavascriptFiles ()
    	{
    		return $this->scriptsAfterLoad;
    	}
    	
    	/**
    	 * This function loads all Tiny MCE files.
    	 * 
    	 * @param stdClass $extraParams
    	 * 
    	 * @return void
    	 */
    	public function loadRichTextEditorFiles (stdClass $extraParams = null)
    	{
    		$this->loadJavascriptFile("js/tiny_mce/tiny_mce.js", "beforeLoad");
    	}
    	
    	/**
    	 * This function loads an javscript file. Can be inserted an external
    	 * file to application.
    	 * 
    	 * @param string $relativePath - the relative path to file. Ex: js/jquery.js
    	 * 
    	 * @return string $script
    	 */
    	public function loadJavascriptFile ($relativePath, $loadMode = 'afterLoad')
    	{
    		$script = '';
    		if($relativePath != '')
    		{
    			$script = '<script type="text/javascript" language="javascript" src="'.$relativePath.'"></script>';
    		}
    		if($loadMode == 'afterLoad')
    		{
    			$this->scriptsAfterLoad[] = $script;
    		}
    		else
    		{
	    		if($loadMode == 'beforeLoad')
	    		{
	    			$this->scriptsBeforeLoad[] = $script;
	    		}
    			else
    			{
    				return $script;
    			}
    		}
    	}
    	
    	public function getHTMLUserBar ()
    	{
    		$html = '';
    		$html.= '<div class="box-top">';
    		
    		$html.= '<div class="box-user-logout">';
    		$html.= '<table border="0" cellpadding="0" width="100%">';
    		$html.= '<tr>';
    		$html.= '<td style="text-align:right;">';
    		$html.= 'Usuário: <b>Carlos</b>';
    		$html.= '</td>';
    		$html.= '<td width="10%" style="text-align:right;">';
    		$html.= '<a href="sair.php">Sair</a>';
    		$html.= '</td>';
    		$html.= '</tr>';
    		$html.= '</table>';
    		$html.= '</div>';
    		
    		$html.= '<div class="clear"></div>';
    		$html.= '</div>';
    		$html.= '<div class="clear"></div>';
    		return $html;
    	}
    	
        public function getHTMLHeader($title = '')
        {
            if($title == '')
            {
                $title = '__TITLE__';
            }
            $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                        		 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                        <html xmlns="http://www.w3.org/1999/xhtml">
                            <head>
                            	<link rel="shortcut icon" href="templates/default/img/bug.png" />
                                <title>'.$title.'</title>
                    	    </head>
                    	<body>
                    		<div class="container">';
            
            return $header;
        }
        
        public function getHTMLClosePage ()
        {
            $close = '
            				</div>	
            			</body>
            		</html>';
            
            return $close;
        }
    }
?>